package org.idea.spring.aop.cglib;

import net.sf.cglib.core.DebuggingClassWriter;
import net.sf.cglib.proxy.Callback;
import net.sf.cglib.proxy.Enhancer;

/**
 * @Author linhao
 * @Date created in 3:59 下午 2021/5/6
 */
public class TestCglib {


    public static void main(String[] args) throws InterruptedException {
        //将生成的字节码文件存放到这个目录下边，查看下会有什么东西
//        System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY,"/Users/linhao/IdeaProjects/framework-project/spring-framework/spring-core/spring-aop/cglib-class");
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(MyBis.class);
        enhancer.setCallback(new TargetInterceptor());
        //多个callback可以参考：https://www.cnblogs.com/xrq730/p/6661692.html
//        enhancer.setCallbacks(new Callback[] {new TargetInterceptor(),new BeforeInterceptor()});
        MyBis myBis = (MyBis) enhancer.create();
        System.out.println("----");
        myBis.doBus();
    }
}
